package com.SeleniumTestsGoogleChrome;

import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.regex.Pattern;

import org.junit.Test;

public class ViewLiveMapTestCases extends SeleneseTestBase {

	@Before
	public void setUp() throws Exception {
		File file = new File(
				"C:/Users/Steven/Documents/4th Year/EECE 419/chromedriver.exe");
		System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
		WebDriver driver = new ChromeDriver();
		String baseUrl = "http://localhost:8080/Website/";
		selenium = new WebDriverBackedSelenium(driver, baseUrl);
	}
	
	// Created by Steven Chow
	// Use Case: Real Time Map
	// Scenario 1: Flight Map Displayed
	// Test Case 1: Map displayed
	@Test
	public void test1() throws Exception {

		selenium.open("");
		// Pre-Setup Expected Result: On page load, check that a login button is
		// present
		assertTrue(selenium
				.isElementPresent("css=div.tile.bg-color-yellow > div.tile-content.icon > img"));

		// Login as Admin
		selenium.click("css=div.tile.bg-color-yellow > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		assertEquals("Flight Manager Login", selenium.getTitle());
		selenium.type("name=id", "1");
		selenium.type("name=password", "pass0");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		// Make sure the Admin can log in
		assertEquals("Manager Portal", selenium.getTitle());
		// Make Sure the Flight Map button is present
		assertTrue(selenium.isElementPresent("css=div.tile-content.icon > img"));
		assertTrue(selenium.isTextPresent("Flight Map"));

		// Logout
		selenium.click("css=div.tile.bg-color-red > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		assertEquals("PlaneSimple", selenium.getTitle());
	}
	
	// Created by Steven Chow
	// Use Case: Real Time Map
	// Scenario 2: Flight Map not Displayed
	// Test Case 1: Map not displayed
	@Test
	public void test9() throws Exception {
		// Go to Website
		selenium.click("css=div.tile.bg-color-yellow > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		selenium.type("name=id", "1");
		selenium.type("name=password", "pass0");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		selenium.open("/Website/index.html");
		// Pre-Setup Expected Result: On page load, check that a login button is
		// present
		assertTrue(selenium
				.isElementPresent("css=div.tile.bg-color-yellow > div.tile-content.icon > img"));

		// Login as Admin
		selenium.click("css=div.tile.bg-color-yellow > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		assertEquals("Flight Manager Login", selenium.getTitle());
		selenium.type("name=id", "1");
		selenium.type("name=password", "pass0");
		selenium.click("css=input[type=\"submit\"]");
		selenium.waitForPageToLoad("30000");
		// Make sure the Admin can log in
		assertEquals("Manager Portal", selenium.getTitle());
		// Make Sure the Flight Map button is present
		assertTrue(selenium.isElementPresent("css=div.tile-content.icon > img"));
		assertTrue(selenium.isTextPresent("Flight Map"));

		// Logout
		selenium.click("css=div.tile.bg-color-red > div.tile-content.icon");
		selenium.waitForPageToLoad("30000");
		assertEquals("PlaneSimple", selenium.getTitle());
	}
	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
